package testArray;
import java.util.Arrays;
import java.util.Scanner;
import java.util.ArrayList;
public class TemporaryVariable {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] arr = new int[]{1, 2, 3, 4, 5, 6, 7, 8};
        System.out.println(Arrays.toString(arr));
        System.out.println("请输入要删除第几个元素：");
        int n = sc.nextInt();
        sc.close();
//把最后一个元素替代指定的元素
        arr[n - 1] = arr[arr.length - 1];
//数组缩容
        arr = Arrays.copyOf(arr, arr.length - 1);
        System.out.println(Arrays.toString(arr));
        ArrayList list = new ArrayList();
        list.add(1);//插入第一个元素
        list.add(2);
        list.add(3);
        list.add(4);
        list.add(6);
        list.add(7);
        list.add(8);
        list.add(0);
        System.out.println(list);//打印list数组
        list.add(4, 5);
        System.out.println(list);
        list.remove(8);
        System.out.println(list);
    }
}